//
//  CPSCAll2CategoryRightViewUIModel.m
//  CollTest
//
//  Created by codew on 11/11/21.
//

#import "CPSCAll2CategoryRightViewUIModel.h"

@interface CPSCAll2CategoryRightViewDataDemo : NSObject <CPSCAll2CategoryRightViewUIModelProtocol>
/** Banner 图片地址 */
@property (nonatomic, strong) NSString * urlBanner;

/** 推荐分类图片 */
@property (nonatomic, strong) NSString * urlRecommend;
/** 推荐分类标题 */
@property (nonatomic, strong) NSString * titleRecommend;

/** 二级分类名字 */
@property (nonatomic, strong) NSString * titleSectionSecond;;
/** 二级分类每个,分类标题 */
@property (nonatomic, strong) NSString * titleSecond;

@property (nonatomic, strong) NSMutableArray <id<CPSCAll2CategoryRightViewUIModelProtocol>>*dataArraySecondItem;
@property (nonatomic, assign) CGFloat cellHeigh;
@end
@implementation CPSCAll2CategoryRightViewDataDemo

/** Banner 图片地址 */
- (NSString *)urlStringBanner
{
    return self.urlBanner;
}

/**
 ====================
 推荐分类
 ====================
 */
// 推荐分类图片
- (NSString *)urlStringRecommend
{
    return _urlRecommend;
}
// 推荐分类标题
- (NSString *)stringTitleRecommend
{
    return _titleRecommend;
}

/**
 ====================
 二级分类
 ====================
 */
// 二级分类名字
- (NSString *)stringTitleSectionSecond
{
    return _titleSectionSecond;
}
///二级分类每个,分类标题
- (NSString *)stringTitleSecond
{
    return _titleSecond;
}

- (NSMutableArray <id<CPSCAll2CategoryRightViewUIModelProtocol>>*)dataItemsSecond
{
    return self.dataArraySecondItem;
}

- (CGFloat)heighCell {
    
    return self.cellHeigh;
}


- (void)updateCellHeight:(CGFloat)height
{
    self.cellHeigh = height;
}
@end


@implementation CPSCAll2CategoryRightViewUIModel


- (NSInteger)countSection
{
    NSInteger count = self.countExceptSecond;
        
    /** 二级分类 */
    count +=  self.dataArraySecond.count;
    
    return count;
}

/** 非二级分类 */
- (NSInteger)countExceptSecond
{
    NSInteger count = 0;
    
    /** Banner */
    BOOL hasBanner = self.dataArrayBanner.count > 0;
    count += hasBanner ? 1 : 0;
    /** 推荐分类 */
    BOOL hasRecommend = self.dataArrayRecommend.count > 0;
    count +=  hasRecommend ? 1 : 0;
    
    return count;
}

+ (instancetype)dataDemo
{
    CPSCAll2CategoryRightViewUIModel * model = [[CPSCAll2CategoryRightViewUIModel alloc] init];
    
    NSArray * bannerImageArr = @[
    @"https://t7.baidu.com/it/u=1819248061,230866778&fm=193&f=GIF",
    @"https://t7.baidu.com/it/u=963301259,1982396977&fm=193&f=GIF",
    @"https://t7.baidu.com/it/u=737555197,308540855&fm=193&f=GIF"
    ];
    
    NSArray * dataIcon = @[
    
        @"https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic2.zhimg.com%2F50%2Fv2-f4d373f0b1ad3692c9e495ab100c0821_hd.jpg&refer=http%3A%2F%2Fpic2.zhimg.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1639297619&t=8da02b70889b853cbff433200f70a216",
        
        @"https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fp9.itc.cn%2Fq_70%2Fimages03%2F20200703%2F7cd179c31d574924a3fa110185791bb7.jpeg&refer=http%3A%2F%2Fp9.itc.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1639297663&t=8005f4718f4be98be11b9798d94b5335",
        
        @"https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fp9.itc.cn%2Fq_70%2Fimages03%2F20200619%2Fa0c3dba1de29443987b68a72145b3382.jpeg&refer=http%3A%2F%2Fp9.itc.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1639297732&t=34ed5c5c5d78c46e4ca577b0c6ee169f",
        
        
        @"https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201807%2F12%2F20180712170406_L8yah.thumb.700_0.png&refer=http%3A%2F%2Fb-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1639297725&t=0624fc350375eea06391b6099b5dc6f5",
        
        @"https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fqqpublic.qpic.cn%2Fqq_public%2F0%2F0-2309376679-3367A8C62AA2C4FED37AEDA07FD2336A%2F0%3Ffmt%3Djpg%26size%3D26%26h%3D441%26w%3D440%26ppv%3D1.jpg&refer=http%3A%2F%2Fqqpublic.qpic.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1639297711&t=ed91fa7eac34734fa511266fb2ffb409",
        
        @"https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic3.zhimg.com%2F50%2Fv2-2bdb993d9d4069605c24d9af019e8723_hd.jpg&refer=http%3A%2F%2Fpic3.zhimg.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1639297853&t=cfc6f253dbdc642fef7479693b73a424"
        
    ];
    
    NSArray<NSString *> *suggestions = @[
        @"公司注册",
        @"代理记账",
        @"许可证服务",
        @"网站建设服务",
        @"个人社保公积金服务",
        @"社保公积金代理"];
    
    NSArray<NSString *> *titleArray = @[
        @"公司注册",
        @"代理记账",
        @"公司变更",
        @"有点无聊",
        @"滚一边去",
        @"验证服务"
    ];
    
    
    //    Banner================================================================================
    NSMutableArray * arrMBanner = [NSMutableArray array];
    for (int i = 0; i < bannerImageArr.count; i++) {

        CPSCAll2CategoryRightViewDataDemo * modelDemo = [[CPSCAll2CategoryRightViewDataDemo alloc] init];
        modelDemo.urlBanner = bannerImageArr[i];

        [arrMBanner addObject:modelDemo];
    }

    model.dataArrayBanner = arrMBanner;
    
    
    //  推荐分类================================================================================
    
    NSMutableArray * arrMRecommend = [NSMutableArray array];
    for (int i = 0; i < 10; i++) {
        
        NSInteger index = arc4random_uniform(dataIcon.count);
        NSString * imageUrl = dataIcon[index];
        
        index = arc4random_uniform(titleArray.count);
        NSString * title = titleArray[index];
        
        CPSCAll2CategoryRightViewDataDemo * modelDemo = [[CPSCAll2CategoryRightViewDataDemo alloc] init];
        
        modelDemo.urlRecommend = imageUrl;
        modelDemo.titleRecommend = title;
        
        [arrMRecommend addObject:modelDemo];
    }

    model.dataArrayRecommend = arrMRecommend;
    
    
    //  二级分类 ================================================================================
    NSMutableArray * arrMSecond = [NSMutableArray array];
    for (int i = 0; i < suggestions.count; i++) {
        
        CPSCAll2CategoryRightViewDataDemo * modelDemo = [[CPSCAll2CategoryRightViewDataDemo alloc] init];
        modelDemo.titleSectionSecond = suggestions[i];
        modelDemo.dataArraySecondItem = [NSMutableArray array];
        
        NSInteger index = arc4random_uniform(40);
        for (int j = 0; j < index; j++) {
            
            CPSCAll2CategoryRightViewDataDemo * modelItem = [[CPSCAll2CategoryRightViewDataDemo alloc] init];
            modelItem.titleSecond = suggestions[arc4random_uniform(suggestions.count)];
            [modelDemo.dataArraySecondItem addObject:modelItem];
        }
        
        [arrMSecond addObject:modelDemo];
    }

    model.dataArraySecond = arrMSecond;
    
    
    return model;
}
@end


